home *** CD-ROM | disk | FTP | other *** search
/ Aminet 39 / Aminet 39 (2000)(Schatztruhe)[!][Oct 2000].iso / Aminet / util / misc / InstallerFXSou.lha / Source Release1.10 / MainCode.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-04  |  31.3 KB  |  1,070 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <exec/libraries.h>
  4. #include <dos/dos.h>
  5. #include <dos/rdargs.h>
  6. #include <datatypes/datatypes.h>
  7. #include <datatypes/datatypesclass.h>
  8. #include <datatypes/pictureclass.h>
  9. #include <datatypes/pictureclassext.h>
  10. #include <intuition/intuition.h>
  11. #include <intuition/icclass.h>
  12. #include <graphics/gfx.h>
  13. #include <graphics/displayinfo.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <stdio.h>
  17. #include <clib/macros.h>
  18. #include <devices/timer.h>
  19. #include <proto/timer.h>
  20. #include <proto/exec.h>
  21. #include <clib/alib_protos.h>
  22. #include <clib/datatypes_protos.h>
  23. #include <clib/dos_protos.h>
  24. #include <clib/exec_protos.h>
  25. #include <clib/graphics_protos.h>
  26. #include <clib/intuition_protos.h>
  27. #include <clib/utility_protos.h>
  28. #include <pragmas/datatypes_pragmas.h>
  29. #include <pragmas/dos_pragmas.h>
  30. #include <pragmas/exec_pragmas.h>
  31. #include <pragmas/graphics_pragmas.h>
  32. #include <pragmas/intuition_pragmas.h>
  33. #include <pragmas/utility_pragmas.h>
  34.  
  35. // Global variables ****************************************************
  36.  
  37. //struct Library *IntuitionBase = NULL;
  38. struct IntuitionBase *IntuitionBase = NULL;
  39. struct Library *GfxBase = NULL;
  40. struct Library *CybergraphicsBase = NULL;
  41. struct Library *DataTypesBase = NULL;
  42. struct Task *mytask;
  43. struct Window *Mywindow;
  44. struct BitMapHeader *mybmhd = NULL;
  45. struct BitMap *mybitmapdt = NULL;
  46. struct BitMap *mybitmapdtReMapped = NULL;
  47. //struct BitMap *Mywindowbitmap = NULL;
  48. Object *mydataobject;
  49. int mywindowX = 0 ;
  50. int mywindowY = 0 ;
  51. int mysignal;
  52. int quit = NULL;
  53. int myinstallertofront = TRUE;
  54. int mycenterX;
  55. int mycenterY;
  56. int myscreenX;
  57. int myscreenY;
  58. int inputpos,myborderless,installerpos,mytile;
  59. int    animwait,animspeed,animframes,animtype;
  60. int calcspeed;
  61. int winbordertop = 1;
  62. int winborderleft = 1;
  63. int mywindowopen = FALSE;
  64. char *myallocmem = 0;
  65. int myopenfile = 0;
  66. int foundwindow = FALSE;
  67. int skipwaitnewfile = FALSE;
  68. int    Cwindowx = 0;
  69. int Cwindowy = 0;
  70. struct Screen *myscreen = 0;
  71. struct Screen *mylockscreen = 0;
  72. STRPTR myprefs = ".prefs";
  73. STRPTR Emptystring = "copy ";
  74. STRPTR Emptystring2 = " to ";
  75. STRPTR Emptystring3 = ".in_use";
  76. STRPTR Emptystring4 = "delete ";
  77. STRPTR Version = "$VER: InstallerFX Version 1.10 (01.10.1997)by Øyvind Falch of Triumph 1997-1998";
  78. STRPTR SearchString = "Install ";
  79. struct Window *otherwindow = NULL;
  80. char mywintitle = NULL;
  81. int Ssearch = TRUE;
  82. char *argallocmem;
  83. char *mypool = NULL;
  84. char *myfilename = NULL;
  85. char *myconfigfile = NULL;
  86. char *mycopystring = NULL;
  87. char *myshowfilename = NULL;
  88. char *mydeletestring = NULL;
  89. int    makestringfailed = TRUE;
  90. int animation = FALSE;
  91. ULONG nomwidth, nomheight;
  92. struct NotifyRequest Filenr  = {0};
  93. BYTE timerdevice = TRUE ;
  94. struct MsgPort *TimerPort = 0;
  95. struct timerequest *TimerReq = 0;
  96. ULONG waitmask;
  97. ULONG sigs;
  98.  
  99. #define    IDCMP_FLAGS    IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY | IDCMP_IDCMPUPDATE
  100.  
  101. // ImageBackfill
  102.  
  103. /*
  104. ** $VER: ImageBackFill.h 1.13 (19.3.95)
  105. **
  106. ** (W) 1992-95 by Pierre Carrette & Walter Dörwald
  107. */
  108.  
  109. struct BackFillOptions
  110. {
  111.     WORD MaxCopyWidth;  // maximum width for the copy
  112.     WORD MaxCopyHeight; // maximum height for the copy
  113.     BOOL CenterX;       // center the tiles horizontally?
  114.     BOOL CenterY;       // center the tiles vertically?
  115.     WORD OffsetX;       // offset to add
  116.     WORD OffsetY;       // offset to add
  117.     BOOL OffsetTitleY;  // add the screen titlebar height to the vertical offset?
  118. };
  119.  
  120. struct BackFillInfo
  121. {
  122.     struct Hook            Hook;
  123.     struct Screen         *Screen;
  124.     Object                *PictureObject;
  125.     struct BitMapHeader   *BitMapHeader;
  126.     struct BitMap         *BitMap;
  127.     WORD                   CopyWidth;
  128.     WORD                   CopyHeight;
  129.     struct BackFillOptions Options;
  130. };
  131.  
  132. struct Rectangle myrec;
  133.  
  134. // ImageBackfill
  135.  
  136. // Program Start ****************************************************************
  137.  
  138. // CopyTiledBitMap
  139. /*
  140. ** $VER: ImageBackFill.c 1.231 (19.3.95)
  141. **
  142. ** (W) 1992-95 by Pierre Carrette & Walter Dörwald
  143. */
  144.  
  145. struct BackFillMsg
  146. {
  147.     struct Layer    *Layer;
  148.     struct Rectangle Bounds;
  149.     LONG             OffsetX;
  150.     LONG             OffsetY;
  151. };
  152.  
  153. // this seems to be a bug (or feature) in SAS/C: -6%5 gives -1 instead of 4
  154.  
  155. #define MOD(x,y) ((x)<0 ? (y)-((-(x))%(y)) : (x)%(y))
  156. #define RECTSIZEX(r) ((r)->MaxX-(r)->MinX+1)
  157. #define RECTSIZEY(r) ((r)->MaxY-(r)->MinY+1)
  158.  
  159. /****** CopyTiledBitMap ****************************************************************************
  160. *
  161. *   NAME
  162. *    CopyTiledBitMap() -- fill bitmap with bitmap pattern
  163. *
  164. *   SYNOPSIS
  165. *    CopyTiledBitMap(Src,SrcOffsetX,SrcOffsetY,SrcSizeX,SrcSizeY,Dst,DstBounds)
  166.  
  167. *    void CopyTiledBitMap(struct BitMap *,WORD,WORD,WORD,WORD,struct BitMap *,struct Rectangle *)
  168. *
  169. *   FUNCTION
  170. *    fills the destination bitmap with repeated (tiled) copies of the source bitmap
  171. *
  172. *   INPUTS
  173. *    Src = source bitmap.
  174. *    SrcOffsetX = offset (in x direction) to use in the blit.
  175. *    SrcOffsetY = offset (in y direction) to use in the blit.
  176. *                 The pixel at position (SrcOffsetX,SrcOffsetY) in the source bitmap
  177. *                 will be the first visible one in the upper left corner of DstBounds.
  178. *    SrcSizeX = width of the source bitmap Src.
  179. *    SrcSizeY = height of the source bitmap Src.
  180. *    Dst = destination bitmap.
  181. *    DstBounds = this rectangle in the destination bitmap will be filled.
  182. *
  183. *   RESULT
  184. *    None.
  185. *
  186. *   EXAMPLE
  187. *    This function is most useful in backfill hooks.
  188. *
  189. *   NOTES
  190. *    The following relations must hold:
  191. *        0 <= SrcOffsetX < SrcSizeX
  192. *        0 <= SrcOffsetY < SrcSizeY
  193. *    I.e. if calculating the offset involves some kind of modulo-operations
  194. *    they have to be done before calling this function
  195. *
  196. */
  197.  
  198. void CopyTiledBitMap(struct BitMap *Src,WORD SrcOffsetX,WORD SrcOffsetY,WORD SrcSizeX,WORD SrcSizeY,struct BitMap *Dst,struct Rectangle *DstBounds)
  199. {
  200.     WORD FirstSizeX;  // the width of the rectangle to blit as the first column
  201.     WORD FirstSizeY;  // the height of the rectangle to blit as the first row
  202.     WORD SecondMinX;  // the left edge of the second column
  203.     WORD SecondMinY;  // the top edge of the second column
  204.     WORD SecondSizeX; // the width of the second column
  205.     WORD SecondSizeY; // the height of the second column
  206.     WORD Pos;         // used as starting position in the "exponential" blit
  207.     WORD Size;        // used as bitmap size in the "exponential" blit
  208.  
  209.     FirstSizeX = MIN(SrcSizeX-SrcOffsetX,RECTSIZEX(DstBounds)); // the width of the first tile, this is either the rest of the tile right to SrcOffsetX or the width of the dest rect, if the rect is narrow
  210.     SecondMinX = DstBounds->MinX+FirstSizeX; // the start for the second tile (if used)
  211.     SecondSizeX = MIN(SrcOffsetX,DstBounds->MaxX-SecondMinX+1); // the width of the second tile (we want the whole tile to be SrcSizeX pixels wide, if we use SrcSizeX-SrcOffsetX pixels for the left part we'll use SrcOffsetX for the right part)
  212.  
  213.     FirstSizeY = MIN(SrcSizeY-SrcOffsetY,RECTSIZEY(DstBounds)); // the same values are calculated for y direction
  214.     SecondMinY = DstBounds->MinY+FirstSizeY;
  215.     SecondSizeY = MIN(SrcOffsetY,DstBounds->MaxY-SecondMinY+1);
  216.  
  217.     BltBitMap(Src,SrcOffsetX,SrcOffsetY,Dst,DstBounds->MinX,DstBounds->MinY,FirstSizeX,FirstSizeY,0xC0,-1,NULL); // blit the first piece of the tile
  218.     if (SecondSizeX>0) // if SrcOffset was 0 or the dest rect was to narrow, we won't need a second column
  219.         BltBitMap(Src,0,SrcOffsetY,Dst,SecondMinX,DstBounds->MinY,SecondSizeX,FirstSizeY,0xC0,-1,NULL);
  220.     if (SecondSizeY>0) // is a second row necessary?
  221.     {
  222.         BltBitMap(Src,SrcOffsetX,0,Dst,DstBounds->MinX,SecondMinY,FirstSizeX,SecondSizeY,0xC0,-1,NULL);
  223.         if (SecondSizeX>0)
  224.             BltBitMap(Src,0,0,Dst,SecondMinX,SecondMinY,SecondSizeX,SecondSizeY,0xC0,-1,NULL);
  225.     }
  226.  
  227.     // this loop generates the first row of the tiles
  228.     for (Pos = DstBounds->MinX+SrcSizeX,Size = MIN(SrcSizeX,DstBounds->MaxX-Pos+1);Pos<=DstBounds->MaxX;)
  229.     {
  230.         BltBitMap(Dst,DstBounds->MinX,DstBounds->MinY,Dst,Pos,DstBounds->MinY,Size,MIN(SrcSizeY,RECTSIZEY(DstBounds)),0xC0,-1,NULL);
  231.         Pos += Size;
  232.         Size = MIN(Size<<1,DstBounds->MaxX-Pos+1);
  233.     }
  234.  
  235.     // this loop blit the first row down several times to fill the whole dest rect
  236.     for (Pos = DstBounds->MinY+SrcSizeY,Size = MIN(SrcSizeY,DstBounds->MaxY-Pos+1);Pos<=DstBounds->MaxY;)
  237.     {
  238.         BltBitMap(Dst,DstBounds->MinX,DstBounds->MinY,Dst,DstBounds->MinX,Pos,RECTSIZEX(DstBounds),Size,0xC0,-1,NULL);
  239.         Pos += Size;
  240.         Size = MIN(Size<<1,DstBounds->MaxY-Pos+1);
  241.     }
  242. }
  243.  
  244. // This function must be compiled without stack checking
  245. void WindowPatternBackFillFunc(register __a0 struct Hook *Hook,register __a2 struct RastPort *RP,register __a1 struct BackFillMsg *BFM)
  246. {
  247.     WORD OffsetX; // the offset within the tile in x direction
  248.     WORD OffsetY; // the offset within the tile in y direction
  249.  
  250.     struct BackFillInfo *BFI = (struct BackFillInfo *)Hook; // get the data for our backfillhook (but __saveds is nonetheless required because this function needs GfxBase)
  251.  
  252.     struct RastPort cRP;
  253.  
  254.     cRP = *RP;        // copy the rastport
  255.     cRP.Layer = NULL; // eliminate bogus clipping from our copy
  256.  
  257.     OffsetX = BFM->Bounds.MinX-BFI->Options.OffsetX; // The first tile normally isn't totally visible => calculate the offset (offset 0 would mean that the left edge of the damage rectangle coincides with the left edge of a tile)
  258.     if (BFI->Options.CenterX) // horizontal centering?
  259.         OffsetX -= (BFI->Screen->Width-BFI->BitMapHeader->bmh_Width)/2;
  260.  
  261.     OffsetY = BFM->Bounds.MinY-BFI->Options.OffsetY; // The same values are calculated for y direction
  262.     if (BFI->Options.OffsetTitleY) // shift the tiles down?
  263.         OffsetY -= BFI->Screen->BarHeight+1;
  264.     if (BFI->Options.CenterY) // horizontal centering?
  265.         OffsetY -= (BFI->Screen->Height-BFI->BitMapHeader->bmh_Height)/2;
  266.  
  267.     CopyTiledBitMap(BFI->BitMap,MOD(OffsetX,BFI->BitMapHeader->bmh_Width),MOD(OffsetY,BFI->BitMapHeader->bmh_Height),BFI->CopyWidth,BFI->CopyHeight,cRP.BitMap,&BFM->Bounds);
  268. }
  269.  
  270. // this function calculates the sizes to be used for the copy of the bitmap
  271. static void CalculateCopySizes(struct BackFillInfo *BFI)
  272. {
  273.     BFI->CopyWidth = (BFI->BitMapHeader->bmh_Width>BFI->Options.MaxCopyWidth) ? BFI->BitMapHeader->bmh_Width : BFI->Options.MaxCopyWidth-BFI->Options.MaxCopyWidth%BFI->BitMapHeader->bmh_Width;
  274.     BFI->CopyHeight = (BFI->BitMapHeader->bmh_Height>BFI->Options.MaxCopyHeight) ? BFI->BitMapHeader->bmh_Height : BFI->Options.MaxCopyHeight-BFI->Options.MaxCopyHeight%BFI->BitMapHeader->bmh_Height;
  275. }
  276. // CopyTiledBitMap
  277.  
  278. // Get args  ****************************************************************
  279. int MakeStrings () // Make Copy String
  280. {
  281.     int mycounter = 0;
  282.     int mycounter2 = 0;
  283.     STRPTR myargs ;
  284.     myargs = GetArgStr ();
  285.     if (myargs[0] != '\n') {
  286.         myfilename = AllocPooled (mypool,512);
  287.         myconfigfile = AllocPooled (mypool,512);
  288.         mycopystring = AllocPooled (mypool,512);
  289.         myshowfilename = AllocPooled (mypool,512);
  290.         mydeletestring = AllocPooled (mypool,512);
  291.         if (myfilename != NULL || myconfigfile != NULL ||mycopystring != NULL ||myshowfilename != NULL ||mydeletestring != NULL){
  292. // Filename
  293.             while ((myargs[mycounter]) != '\n'){
  294.                 myfilename[mycounter] = myargs[mycounter];
  295.                 myconfigfile[mycounter] = myargs[mycounter];
  296.                 mycounter = mycounter +1;
  297.             }
  298.             while ((myprefs[mycounter2]) != 0){
  299.                 myconfigfile[mycounter] = myprefs[mycounter2];
  300.                 mycounter = mycounter +1;
  301.                 mycounter2 = mycounter2 +1;
  302.             }
  303. // Copystring
  304.             mycounter = 0;
  305.             mycounter2 = 0;
  306. // copy >nil: <nil: 
  307.             while ((Emptystring[mycounter]) != 0){
  308.                 mycopystring[mycounter] = Emptystring[mycounter];
  309.                 mycounter = mycounter +1;
  310.             }
  311. // filename
  312.             while ((myfilename[mycounter2]) != 0){
  313.                 mycopystring[mycounter] = myfilename[mycounter2];
  314.                 mycounter = mycounter +1;
  315.                 mycounter2 = mycounter2 +1;
  316.             }
  317. // " to "
  318.             mycounter2 = 0;
  319.             while ((Emptystring2[mycounter2]) != 0){
  320.                 mycopystring[mycounter] = Emptystring2[mycounter2];
  321.                 mycounter = mycounter +1;
  322.                 mycounter2 = mycounter2 +1;
  323.             }
  324. // filename 
  325.             mycounter2 = 0;
  326.             while ((myfilename[mycounter2]) != 0){
  327.                 mycopystring[mycounter] = myfilename[mycounter2];
  328.                 mycounter = mycounter +1;
  329.                 mycounter2 = mycounter2 +1;
  330.             }
  331. // ".in_use
  332.             mycounter2 = 0;
  333.             while ((Emptystring3[mycounter2]) != 0){
  334.                 mycopystring[mycounter] = Emptystring3[mycounter2];
  335.                 mycounter = mycounter +1;
  336.                 mycounter2 = mycounter2 +1;
  337.             }
  338.             mycounter = 0;
  339.             mycounter2 = 0;
  340. // filename
  341.             while ((myfilename[mycounter]) != 0){
  342.                 myshowfilename[mycounter] = myfilename[mycounter];
  343.                 mycounter = mycounter +1;
  344.             }
  345. // ".in_use
  346.             while ((Emptystring3[mycounter2]) != 0){
  347.                 myshowfilename[mycounter] = Emptystring3[mycounter2];
  348.                 mycounter = mycounter +1;
  349.                 mycounter2 = mycounter2 +1;
  350.             }
  351. // Delete String
  352.             mycounter = 0;
  353.             mycounter2 = 0;
  354. // "delete >nil: <nil: "
  355.             while ((Emptystring4[mycounter]) != 0){
  356.                 mydeletestring[mycounter] = Emptystring4[mycounter];
  357.                 mycounter = mycounter +1;
  358.             }
  359. // filename
  360.             while ((myfilename[mycounter2]) != 0){
  361.                 mydeletestring[mycounter] = myfilename[mycounter2];
  362.                 mycounter = mycounter +1;
  363.                 mycounter2 = mycounter2 +1;
  364.             }
  365. // ".in_use
  366.             mycounter2 = 0;
  367.             while ((Emptystring3[mycounter2]) != 0){
  368.                 mydeletestring[mycounter] = Emptystring3[mycounter2];
  369.                 mycounter = mycounter +1;
  370.                 mycounter2 = mycounter2 +1;
  371.             }
  372.             makestringfailed = FALSE;
  373.         }
  374.     }
  375.     return 0;
  376. }
  377. // checknext window  ****************************************************************
  378. int checkNextwindow () // Find Installer window before move
  379. {
  380.     UBYTE pattern[] = "*installer*";
  381.     UBYTE pat[(sizeof(pattern)*2)+2];
  382.  
  383.     ParsePatternNoCase(pattern, pat, (sizeof(pattern)*2)+2);
  384.   if(MatchPatternNoCase(pat, ((struct Task *) otherwindow->UserPort->mp_SigTask)->tc_Node.ln_Name))    
  385.         Ssearch = TRUE;
  386.     else
  387.         Ssearch = FALSE;
  388.         
  389.     return 0;
  390. }
  391.  
  392. // Move Installer Window  ****************************************************************
  393. int calculate_windows ()  // Calculate Installer Window on screen
  394. {
  395.     int install_WX = 0;
  396.     int install_WY = 0;
  397.     int    installc_X = 0;
  398.     int installc_Y = 0;
  399.  
  400.     install_WX = otherwindow->Width;
  401.     install_WY = otherwindow->Height;
  402.     installc_X = otherwindow->LeftEdge;
  403.     installc_Y = otherwindow->TopEdge;
  404.     
  405. // Top 
  406.     if (installerpos == 1){
  407.         installc_X = ((myscreenX/4) - (install_WX /2)) - installc_X;
  408.         installc_Y = ((myscreenY/4) - (install_WY /2)) - installc_Y;
  409.         }
  410.     else if (installerpos == 2){
  411.         installc_X = ((myscreenX/2) - (install_WX /2)) - installc_X;
  412.         installc_Y = ((myscreenY/4) - (install_WY /2)) - installc_Y;
  413.         }
  414.     else if (installerpos == 3){
  415.         installc_X = (((myscreenX/4)*3) - (install_WX /2)) - installc_X;
  416.         installc_Y = ((myscreenY/4) - (install_WY /2)) - installc_Y;
  417.         }
  418. // Middle
  419.     else if (installerpos == 4){
  420.         installc_X = ((myscreenX/4) - (install_WX /2)) - installc_X;
  421.         installc_Y = ((myscreenY/2) - (install_WY /2)) - installc_Y;
  422.         }
  423.     else if (installerpos == 5){
  424.         installc_X = ((myscreenX/2) - (install_WX /2)) - installc_X;
  425.         installc_Y = ((myscreenY/2) - (install_WY /2)) - installc_Y;
  426.         }
  427.     else if (installerpos == 6){
  428.         installc_X = (((myscreenX/4)*3) - (install_WX /2)) - installc_X;
  429.         installc_Y = ((myscreenY/2) - (install_WY /2)) - installc_Y;
  430.         }
  431. // Bottom
  432.     else if (installerpos == 7){
  433.         installc_X = ((myscreenX/4) - (install_WX /2)) - installc_X;
  434.         installc_Y = (((myscreenY/4)*3) - (install_WY /2)) - installc_Y;
  435.         }
  436.     else if (installerpos == 8){
  437.         installc_X = ((myscreenX/2) - (install_WX /2)) - installc_X;
  438.         installc_Y = (((myscreenY/4)*3) - (install_WY /2)) - installc_Y;
  439.         }
  440.     else if (installerpos == 9){
  441.         installc_X = (((myscreenX/4)*3) - (install_WX /2)) - installc_X;
  442.         installc_Y = (((myscreenY/4)*3) - (install_WY /2)) - installc_Y;
  443.         }
  444.     else if (installerpos == 0) {
  445.         installc_X = 0;
  446.         installc_Y = 0;
  447.         }
  448.     MoveWindow( otherwindow, installc_X, installc_Y );
  449.     WindowToFront (otherwindow);
  450.     return 0;
  451. }
  452. // Move Installer Window  ****************************************************************
  453. int moveInstaller () // Move installer window
  454. {
  455.     struct Screen *lockmove;
  456.     lockmove = LockPubScreen ("Workbench");
  457.  
  458.     myscreenX = lockmove ->Width;
  459.     myscreenY = lockmove ->Height;
  460.  
  461.     for (otherwindow = lockmove->FirstWindow; otherwindow; 
  462.         otherwindow = otherwindow->NextWindow) {
  463.         if (otherwindow->Title) {
  464.                 checkNextwindow ();
  465.             if (Ssearch !=FALSE){
  466.                 calculate_windows ();
  467.                 break;
  468.             }            
  469.         }
  470.     }
  471.     UnlockPubScreen (NULL, lockmove);
  472.     return 0;
  473. }
  474.  
  475. // NOTIFY ***************************************************
  476. int notify(char*waitfile)
  477. {
  478.     struct NotifyRequest nr  = {0};
  479.     nr.nr_Flags = NRF_SEND_SIGNAL;
  480.     nr.nr_stuff.nr_Signal.nr_Task = mytask;
  481.     nr.nr_stuff.nr_Signal.nr_SignalNum = mysignal;
  482.     nr.nr_Name  = waitfile;
  483.     StartNotify ( &nr );
  484.     Wait (1 <<mysignal);
  485.     EndNotify ( &nr);
  486.     return 0;
  487. }
  488.  
  489. // NOTIFY Anim ***************************************************
  490. int notifyAnim(char*waitfile)
  491. {
  492.     Filenr.nr_Flags = NRF_SEND_SIGNAL;
  493.     Filenr.nr_stuff.nr_Signal.nr_Task = mytask;
  494.     Filenr.nr_stuff.nr_Signal.nr_SignalNum = mysignal;
  495.     Filenr.nr_Name  = waitfile;
  496.     StartNotify ( &Filenr );
  497.     return 0;
  498. }
  499.  
  500. // Wait Function  ****************************************************************
  501. int CreateTimerWait(void)
  502. {
  503.     timerdevice = TRUE ;
  504.     TimerPort = 0;
  505.     TimerReq = 0;
  506.     waitmask =0 ;
  507.     sigs =0 ;
  508.     
  509.     // Opprette en svarport for timerequest
  510.     TimerPort =  CreateMsgPort();
  511.     if( TimerPort != 0) {
  512.         // Opprette en timerequest som kan sendes til devicen
  513.         TimerReq =  (struct timerequest *) 
  514.         CreateIORequest( TimerPort, sizeof (struct timerequest) );
  515.         if( TimerReq != 0) {
  516.             timerdevice =  OpenDevice( "timer.device", 
  517.             // Åpne et eller annet device
  518.             UNIT_VBLANK, (struct IORequest *) TimerReq, 0 );
  519.             if( timerdevice == 0) {
  520.                 TimerReq->tr_node.io_Message.mn_Node.ln_Type =  0;            
  521.             }
  522.         }
  523.     }
  524.     return 0;
  525. }
  526.  
  527. // Wait Function  ****************************************************************
  528. WaitTimer(void)
  529. {
  530. // timer.device er nå åpen.
  531. //   printf( "sender request for 10 sekunders venting til timer.device...\n" );
  532.  
  533.     waitmask = 0 ;
  534.     sigs = 0 ;
  535.  
  536.     waitmask =  (1 << TimerPort->mp_SigBit) | SIGBREAKF_CTRL_C | 1 <<mysignal ;
  537.  
  538.     TimerReq->tr_node.io_Command =  TR_ADDREQUEST;
  539.     TimerReq->tr_time.tv_secs  =  animwait;
  540.     TimerReq->tr_time.tv_micro = calcspeed;
  541.  
  542.     SendIO( (struct IORequest *) TimerReq );
  543.  
  544. //   printf( "request er sendt. Tikk tikk tikk...\n" );
  545.  
  546.    // Setter opp hvilke bits vi vil vente på.
  547.    // Alle prosesser kan også vente på SIGBREAKF_CTRL_? signalene, som tilsvarer
  548.    // CTRL_C etc.
  549.    // Her kan du legge inn masks for andre ting du vil vente p=å.
  550.  
  551. //   printf( "Bruker Wait() for å vente på både ctrl-c og svar på requesten\n" );
  552.  
  553.     sigs =  Wait( waitmask );
  554.  
  555.    // Husk at vi kan få både ctrl-c + vent ferdig som svar hvis ctrl-c blir
  556.    // trykket akkurat i det timeren er ferdig.
  557.  
  558. //    printf( "Signalmaske mottatt: %x\n", sigs );
  559.  
  560.     return 0;
  561. }
  562.  
  563. // Wait Function  ****************************************************************
  564. CleanupTimerWait(void)
  565. {
  566.   // Rydde opp...
  567.     if (timerdevice == 0)
  568.         CloseDevice( (struct IORequest *)TimerReq );
  569.     if (!TimerReq != 0)
  570.         DeleteIORequest( (struct IORequest *)TimerReq );
  571.     if (!TimerPort != 0)
  572.        DeleteMsgPort( TimerPort );
  573. //   printf( "ferdig!\n" );
  574.    return 0;
  575. }
  576.  
  577. // Load file Simple ****************************************************************
  578. int readprefsfile ()
  579. {
  580.     FILE    *fp;
  581.     int     ant_poster;
  582.     inputpos = 0;
  583.     myborderless = 0;
  584.     installerpos = 0;
  585.     mytile = 0;;
  586.     animspeed = 0;
  587.     animframes = 0;
  588.     animtype = 0;
  589.     animation = FALSE;
  590.     fp= fopen(myconfigfile, "r");
  591.     if (fp != NULL){ 
  592.         ant_poster = fscanf(fp,"%1d%1d%1d%1d%02d%03d%03d%0d3\n",&inputpos,&myborderless,&mytile,&installerpos,&animwait,&animspeed,&animframes,&animtype);
  593.         fclose (fp);
  594.     //        printf ("Can't load prefsfile, using default values.\n");
  595.     }    
  596.     if (inputpos >9 || inputpos < 1)
  597.         inputpos = 1;
  598.     if (myborderless >1 || myborderless <0)
  599.         myborderless = 0;
  600.     if (installerpos >9 || installerpos <0)
  601.         installerpos = 9;
  602.     if (mytile >1 || mytile <0)
  603.         mytile = 0;
  604.     if (animwait  >999 || animwait <0)
  605.         animwait = 0;
  606.     if (animspeed  >99 || animspeed <0)
  607.         animspeed = 0;
  608.     if (animframes  >999 || animframes <0)
  609.         animframes = 0;
  610.     if (animtype  >999 || animtype <0)
  611.         animtype = 0;
  612.     if (animframes >0 && animframes >0)
  613.         animation = TRUE;
  614.     // Extra check for Second and Frames.
  615.     if (animwait >0)
  616.         animspeed = 0;
  617.     if (animwait == 0 && animspeed == 0)
  618.         animwait = 5;         
  619.     return 0;
  620. }
  621.  
  622. // Copy File ***************************************************
  623. int mycopyfile()
  624. {
  625.     Execute (mycopystring,NULL,NULL);
  626.     return 0;
  627. }
  628.  
  629. // Delete File ***************************************************
  630. int mydeletefile()
  631. {
  632.     Execute (mydeletestring,NULL,NULL);
  633.     return 0;
  634. }
  635.  
  636. // Wait for datatype Calculations *****************************
  637. wait_for_datatype ()
  638. {
  639.     BOOL going = TRUE;
  640.     LONG sigr;    
  641.     struct IntuiMessage *imsg;
  642.     struct TagItem *tstate, *tag;
  643.     struct TagItem *tags;
  644.     ULONG tidata;
  645.     ULONG errnum;
  646. //    ULONG options[NUM_OPTS];
  647.  
  648.     /* Keep going until were told to stop */
  649.  
  650.     while (going)
  651.  
  652.     {
  653.         /* Wait for an event */
  654.         sigr = Wait ((1L << Mywindow->UserPort->mp_SigBit) | SIGBREAKF_CTRL_C);
  655.         
  656.         /* Did we get a break signal */
  657.         if (sigr & SIGBREAKF_CTRL_C)
  658.             going = FALSE;
  659.     
  660.         /* Pull Intuition messages */
  661.         while (imsg = (struct IntuiMessage *) GetMsg (Mywindow->UserPort))
  662.             {
  663.             /* Handle each message */
  664.             switch (imsg->Class)
  665.                 {
  666.                     case IDCMP_CLOSEWINDOW:
  667.                     going = FALSE;
  668.     
  669.                     break;
  670.                     case IDCMP_VANILLAKEY:
  671.                     switch (imsg->Code)
  672.                         {
  673.                            case 'Q':
  674.                           case 'q':
  675.                           case  27:
  676.                             going = FALSE;
  677.                             break;
  678.                         }
  679.                         break;
  680.     
  681.                       case IDCMP_IDCMPUPDATE:
  682.                         tstate = tags = (struct TagItem *) imsg->IAddress;
  683.                         while (tag = NextTagItem (&tstate))
  684.                         {
  685.                             tidata = tag->ti_Data;
  686.                             switch (tag->ti_Tag)
  687.                             {
  688.                                 /* Change in busy state */
  689.                                 case DTA_Busy:
  690.                                 if (tidata)
  691.                                     SetWindowPointer (Mywindow, WA_BusyPointer, TRUE, TAG_DONE);
  692.                                 else
  693.                                     SetWindowPointer (Mywindow, WA_Pointer, NULL, TAG_DONE);
  694.                                 break;
  695.     
  696.                                 /* Error message */
  697.                                 case DTA_ErrorLevel:
  698.                                 if (tidata)
  699.                                 {
  700.                                     errnum = GetTagData (DTA_ErrorNumber, NULL, tags);
  701. //                                    PrintErrorMsg (errnum, (STRPTR) options[OPT_NAME]);
  702.                                 }
  703.                                 break;
  704.  
  705.                                 /* Time to refresh */
  706.                                 case DTA_Sync:
  707.                                 /* Refresh the DataType object */
  708. //                                RefreshDTObjectA (mydataobject, Mywindow, NULL, NULL);
  709.                                 going = FALSE;
  710.                                 break;
  711.                             }
  712.                         }
  713.                         break;
  714.                 }
  715.     
  716.                 /* Done with the message, so reply to it */
  717.                 ReplyMsg ((struct Message *) imsg);
  718.             }
  719.     }
  720.     return 0;
  721. }
  722.  
  723. // Get Screen Information and move installer window **************
  724. int get_screen_information ()
  725. {
  726.     struct Screen *getscreenlock;
  727.     getscreenlock = LockPubScreen ("Workbench");
  728.     if (getscreenlock != 0){
  729.         myscreen = getscreenlock;
  730.         myscreenX = getscreenlock ->Width;
  731.         myscreenY = getscreenlock ->Height;
  732.         if (myborderless == FALSE){
  733.             winbordertop = getscreenlock->WBorTop;
  734.             winborderleft = getscreenlock->WBorLeft;
  735.         }
  736.         UnlockPubScreen (NULL, getscreenlock);
  737.     }
  738.     else
  739.         quit = 1;
  740.     return 0;
  741. }
  742.  
  743. // Calculate Window  ********************************************
  744.  
  745. int calculate_window ()
  746. {
  747.     GetDTAttrs (mydataobject, PDTA_BitMapHeader,&mybmhd,PDTA_BitMap,&mybitmapdt, TAG_END);
  748.  
  749.     mywindowX = mybmhd ->bmh_Width;
  750.     mywindowY = mybmhd ->bmh_Height;
  751.  
  752.     nomwidth = mywindowX;
  753.     nomheight = mywindowY;
  754.     
  755.     // Fix place for anim
  756.     if (animation == TRUE) {
  757.         mywindowX = mywindowX/animframes;
  758.     }
  759.     
  760. // Top 
  761.     if (inputpos == 1){
  762.         mycenterX = ((myscreenX/4) - (mywindowX /2));
  763.         mycenterY = ((myscreenY/4) - (mywindowY /2));
  764.         }
  765.     else if (inputpos == 2){
  766.         mycenterX = ((myscreenX/2) - (mywindowX /2));
  767.         mycenterY = ((myscreenY/4) - (mywindowY /2));
  768.     }
  769.     else if (inputpos == 3){
  770.         mycenterX = (((myscreenX/4)*3) - (mywindowX /2));
  771.         mycenterY = ((myscreenY/4) - (mywindowY /2));
  772.     }
  773. // Middle
  774.     else if (inputpos == 4){
  775.         mycenterX = ((myscreenX/4) - (mywindowX /2));
  776.         mycenterY = ((myscreenY/2) - (mywindowY /2));
  777.         }
  778.     else if (inputpos == 5){
  779.         mycenterX = ((myscreenX/2) - (mywindowX /2));
  780.         mycenterY = ((myscreenY/2) - (mywindowY /2));
  781.     }
  782.     else if (inputpos == 6){
  783.         mycenterX = (((myscreenX/4)*3) - (mywindowX /2));
  784.         mycenterY = ((myscreenY/2) - (mywindowY /2));
  785.     }
  786. // Bottom
  787.     else if (inputpos == 7){
  788.         mycenterX = ((myscreenX/4) - (mywindowX /2));
  789.         mycenterY = (((myscreenY/4)*3) - (mywindowY /2));
  790.         }
  791.     else if (inputpos == 8){
  792.         mycenterX = ((myscreenX/2) - (mywindowX /2));
  793.         mycenterY = (((myscreenY/4)*3) - (mywindowY /2));
  794.     }
  795.     else if (inputpos == 9){
  796.         mycenterX = (((myscreenX/4)*3) - (mywindowX /2));
  797.         mycenterY = (((myscreenY/4)*3) - (mywindowY /2));
  798.     }        
  799.     return 0;
  800. }
  801.  
  802. // Process Picture **********************************************
  803. int process_picture ()
  804. {
  805.     struct RastPort *MyRastPort;
  806.     struct Screen *MyScreen;
  807.   struct ViewPort *MyViewPort;
  808.     struct ColorMap *MyColorMap;
  809.     int place_Top;
  810.     int place_Left;
  811.  
  812.     quit = 1;
  813.     get_screen_information ();
  814.     place_Top = winbordertop;
  815.     place_Left = winborderleft;
  816.     if (myborderless ==1) {
  817.         place_Top = 0;
  818.         place_Left = 0;
  819.     }
  820.     mydataobject = NewDTObject(myshowfilename,
  821.                                                             DTA_SourceType,DTST_FILE,
  822.                                                             PDTA_DestMode,MODE_V43,
  823.                                                             DTA_GroupID,GID_PICTURE,
  824.                                                             OBP_Precision,PRECISION_EXACT,
  825.                                                             PDTA_FreeSourceBitMap,TRUE,
  826.                                                             PDTA_Remap,TRUE,
  827.                                                             GA_Top,place_Top,
  828.                                                             GA_Left,place_Left,
  829.                                                             TAG_END ) ;
  830.     if (mydataobject != NULL ) {
  831.         calculate_window ();
  832.         if (mytile ==1 ){
  833.             Mywindow = OpenWindowTags(NULL,
  834.                                                         WA_Left,0,
  835.                                                         WA_Top, 0,
  836.                                                        WA_InnerWidth,myscreenX,
  837.                                                        WA_InnerHeight,myscreenY,
  838.                                                        WA_Borderless,TRUE,
  839.                                                       WA_SmartRefresh,TRUE,
  840.                                                       WA_IDCMP, IDCMP_FLAGS,
  841.                                                        TAG_END ) ;
  842.         }
  843.         else if (mytile !=1 ){
  844.             Mywindow = OpenWindowTags(NULL,
  845.                                                         WA_Left,mycenterX,
  846.                                                         WA_Top, mycenterY,
  847.                                                        WA_InnerWidth,mywindowX,
  848.                                                        WA_InnerHeight,mywindowY,
  849.                                                        WA_Borderless,myborderless,
  850.                                                        WA_SmartRefresh,TRUE,
  851.                                                     WA_IDCMP,IDCMP_FLAGS,
  852.                                                        TAG_END ) ;
  853.         }
  854.         
  855.         if (Mywindow != NULL ){    
  856.             mywindowopen = TRUE;
  857.             MyRastPort = Mywindow->RPort;
  858.             MyScreen = Mywindow->WScreen;
  859.           MyViewPort = &MyScreen->ViewPort;
  860.             MyColorMap = MyViewPort->ColorMap;
  861.             SetDTAttrs (mydataobject, NULL, NULL,
  862.                                 GA_Width,    nomwidth,
  863.                                 GA_Height, nomheight,
  864.                                 ICA_TARGET,    ICTARGET_IDCMP,
  865.                                 TAG_DONE);
  866.  
  867.             AddDTObject (Mywindow, NULL, mydataobject, -1);
  868.             wait_for_datatype (); 
  869.             // Refresh the DataType object since wait for datatype skips this.
  870.         RefreshDTObjectA (mydataobject, Mywindow, NULL, NULL);
  871.             if (mytile == 1) {
  872.                 myrec.MinX = 0;
  873.                 myrec.MinY = 0;
  874.                 myrec.MaxX = myscreenX-1;
  875.                 myrec.MaxY = myscreenY-1;
  876.                 GetDTAttrs (mydataobject,PDTA_DestBitMap,&mybitmapdtReMapped,TAG_END);
  877.                 if (mybitmapdtReMapped != 0){
  878.                     CopyTiledBitMap (mybitmapdtReMapped,0,0,mywindowX,mywindowY,MyRastPort->BitMap, &myrec);
  879.                 }
  880.                 WindowToBack (Mywindow); //Move the background window to back
  881.             }
  882.             // Move the installerwindow after the new window is opened.
  883.             moveInstaller ();            //Move installer Window
  884.             quit = 0;
  885.         }
  886.     }
  887.     return 0;
  888. }
  889.  
  890. // Process Animation **********************************************
  891. int process_anim ()
  892. {
  893.     struct RastPort *MyRastPort;
  894.     struct Screen *MyScreen;
  895.   struct ViewPort *MyViewPort;
  896.     struct ColorMap *MyColorMap;
  897.     int place_Top;
  898.     int place_Left;
  899.     int mydestX = 0;
  900.     int i = 0;
  901.     int n = 0;    
  902.     quit = 1;
  903.     get_screen_information ();
  904.     place_Top = winbordertop;
  905.     place_Left = winborderleft;
  906.     if (myborderless ==1) {
  907.         place_Top = 0;
  908.         place_Left = 0;
  909.     }
  910.     mydataobject = NewDTObject(myshowfilename,
  911.                                                             DTA_SourceType,DTST_FILE,
  912.                                                             PDTA_DestMode,MODE_V43,
  913.                                                             DTA_GroupID,GID_PICTURE,
  914.                                                             PDTA_Screen,myscreen,
  915.                                                             PDTA_FreeSourceBitMap,TRUE,
  916.                                                             OBP_Precision,PRECISION_EXACT,
  917.                                                             PDTA_Remap,TRUE,
  918.                                                             GA_Top,place_Top,
  919.                                                             GA_Left,place_Left,
  920.                                                             TAG_END ) ;
  921.     if (mydataobject != NULL ) {
  922.         calculate_window ();
  923.         Mywindow = OpenWindowTags(NULL,
  924.                                                     WA_Left,mycenterX,
  925.                                                     WA_Top, mycenterY,
  926.                                                    WA_InnerWidth,mywindowX,
  927.                                                    WA_InnerHeight,mywindowY,
  928.                                                    WA_Borderless,myborderless,
  929.                                                 WA_SmartRefresh,TRUE,
  930.                                                 WA_IDCMP,IDCMP_FLAGS,
  931.                                                    TAG_END ) ;
  932.         
  933.         if (Mywindow != NULL ){    
  934.             mywindowopen = TRUE;
  935.             MyRastPort = Mywindow->RPort;
  936.             MyScreen = Mywindow->WScreen;
  937.           MyViewPort = &MyScreen->ViewPort;
  938.             MyColorMap = MyViewPort->ColorMap;
  939.             // Have to move the installer before the animation but after
  940.             // openwindow
  941.             moveInstaller ();            //Move installer Window
  942.             myrec.MinX = 0;
  943.             myrec.MinY = 0;
  944.             myrec.MaxX = mywindowX;;
  945.             myrec.MaxY = mywindowY;
  946.             if (DoMethod(mydataobject, DTM_PROCLAYOUT, NULL, 1)) {
  947.                 GetDTAttrs (mydataobject, PDTA_DestBitMap,&mybitmapdtReMapped, TAG_END); // Getting remapped bitmap
  948.                 if (mybitmapdtReMapped != 0){
  949.                     //    Alloc Timerdevice
  950.                     CreateTimerWait();
  951.                     if (timerdevice == 0) {
  952.                         //    Filenotify Start.
  953.                         notifyAnim (myfilename);        
  954.                         skipwaitnewfile = FALSE;
  955.                         if (animspeed == 0)
  956.                             calcspeed = 0;
  957.                         else
  958.                             calcspeed = 1000000/animspeed;
  959.                         for (n=0;n<=animtype;n++){
  960.                             for (i=0;i<=animframes-1;i++){
  961.                                 BltBitMapRastPort (mybitmapdtReMapped,mydestX,0,MyRastPort,place_Left,place_Top,mywindowX,mywindowY,0x0C0);
  962.                                 // Timerwait, Waiting for Filenotify + time +ctrl c
  963.                                 WaitTimer();
  964.                                 if( sigs & SIGBREAKF_CTRL_C ) {
  965.                                     //     printf( "Ctrl-C ble trykket!\n" );
  966.                                     i = 1000;
  967.                                     n = 1000;
  968.                                 }
  969.                                 //    if( sigs & (1<<TimerPort->mp_SigBit) ) {
  970.                                 //    printf( "Timer wait ok!\n" );
  971.                                 //    }
  972.                                 if( sigs & 1 <<mysignal ) {
  973.                                     //     printf( "Filenotify !\n" );        // Aborting loop !
  974.                                     i = 1000;
  975.                                     n = 1000;
  976.                                     skipwaitnewfile = TRUE;
  977.                                 }
  978.                            // Gjør ikke noe om man tar AbortIO() på en request som er ferdig eller ubrukt!
  979.                                 AbortIO( (struct IORequest *) TimerReq );                    
  980.                                 mydestX = mydestX + mywindowX;
  981.                             }
  982.                             mydestX = 0;
  983.                         }
  984.                         //    Endfilenotify !            
  985.                         EndNotify ( &Filenr);
  986.                     }
  987.                     //    Cleanup Timerdevice
  988.                     CleanupTimerWait();
  989.                     quit = 0;
  990.                     if (timerdevice != 0) {
  991.                         skipwaitnewfile = TRUE;
  992.                         quit = 1;
  993.                     }
  994.                 }
  995.             }
  996.         }
  997.     }
  998.     return 0;
  999. }
  1000. // My Wait ********************************************
  1001. // The program will go throu this loop 2 times when changing picture.
  1002.  
  1003. int wait_for_picture ()
  1004. {
  1005.     // Close window and remove dt object if window is open.
  1006.     if (mywindowopen == TRUE) { 
  1007.         if (skipwaitnewfile != TRUE)
  1008.             notify (myfilename);
  1009.         CloseWindow (Mywindow);
  1010.         RemoveDTObject (Mywindow, mydataobject);
  1011.         DisposeDTObject (mydataobject);
  1012.         mywindowopen = FALSE;
  1013.         mydeletefile ();
  1014.     }
  1015.  
  1016.     // A new file have been copied or deleted
  1017.     else    {
  1018.         mycopyfile ();                //Copy picture
  1019.         readprefsfile ();        //Read config file
  1020.         if (animation == FALSE) {
  1021.             process_picture ();        //Process
  1022.             }
  1023.         // If prefsfile is an anim type then goto anim
  1024.         else {
  1025.             process_anim ();
  1026.         }    
  1027.     }
  1028.     return 0;
  1029. }
  1030.  
  1031. // Main ********************************************************
  1032.  
  1033. void main (int argc, char **argv)
  1034.  
  1035. {
  1036.     mytask = FindTask (NULL);
  1037.     mysignal = AllocSignal (-1);
  1038.     if (mysignal != -1) {
  1039.  
  1040.         IntuitionBase = (struct IntuitionBase*) OpenLibrary("intuition.library", 39);
  1041.         if (IntuitionBase != NULL) {
  1042.  
  1043.             DataTypesBase = OpenLibrary("datatypes.library", 39);
  1044.             if (DataTypesBase != NULL ) {
  1045.         
  1046.                 GfxBase = OpenLibrary("graphics.library",39); 
  1047.                 if (GfxBase != NULL ) { 
  1048.  
  1049.                     mypool = CreatePool(MEMF_PUBLIC|MEMF_CLEAR,512,512);
  1050.                     if (mypool != NULL) {
  1051.  
  1052.                         MakeStrings ();
  1053.                         if (makestringfailed == FALSE ) {
  1054.                             get_screen_information ();
  1055.                             while (quit == NULL)                                                            // Main wait loop
  1056.                                 wait_for_picture ();
  1057.                         }
  1058.                         DeletePool(mypool);
  1059.                     }
  1060.               }
  1061.                  CloseLibrary(GfxBase);
  1062.             }
  1063.             CloseLibrary(DataTypesBase);    
  1064.       }
  1065.       CloseLibrary ((struct Library*) (IntuitionBase));
  1066.   }
  1067.     FreeSignal (mysignal);
  1068. }
  1069.  
  1070.